package com.ruipengkj.component.page;

import javax.swing.JPanel;

import com.ruipengkj.commons.base.query.PageView;

public abstract class AbstractPageDelegale<T> extends JPanel implements PageDelegale{
	
	private static final long serialVersionUID = 1L;

	//首页
	@Override
	public void homePage() {
		this.termQuery(1);
	}
	//尾页
	@Override
	public void lastPage() {
		this.termQuery((int)getPageView().getTotalPage());
	}
	//下一页
	@Override
	public void nextPage() {
		if(getPageView().getCurrentPage()>=getPageView().getTotalPage()){
			this.termQuery((int)getPageView().getTotalPage());
		}else{
			this.termQuery(getPageView().getCurrentPage()+1);
		}
	}
	//上一页
	@Override
	public void prevPage() {
		if(getPageView().getCurrentPage()<=1){
			this.termQuery(1);
		}else{
			this.termQuery(getPageView().getCurrentPage()-1);
		}
	}

	@Override
	public String getInfo() {
		return "当前第 "+getPageView().getCurrentPage()+" 页/共 " +getPageView().getTotalPage()+" 页";
	}
	
	protected abstract void termQuery(int currentPage);
	
	protected abstract PageView<T> getPageView();
	
}
